﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;

namespace Treasures
{
    public class ChipSelection : BaseElement
    {
        #region Fields and Props
        public static string[] BitmapPath { get; protected set; }
        #endregion

        #region public methods

        public override void DrawElementFigure(Graphics g, int x, int y)
        {
            if (this.FigureBitmap != null)
            {
                this.FigureBitmap.MakeTransparent();

                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.DrawImage(this.FigureBitmap, new Rectangle(x + (int)(this.FigureBitmap.Size.Width * ((1 - Scale) / 2)), y + (int)(this.FigureBitmap.Size.Width * ((1 - Scale) / 2)), (int)(this.FigureBitmap.Size.Width * Scale), (int)(this.FigureBitmap.Size.Height * Scale)), 0, 0, this.FigureBitmap.Size.Width, this.FigureBitmap.Size.Height, GraphicsUnit.Pixel);
            }
            else
            {
                throw new IOException("File not found or cant be read. FigureBitmap is null.");
            }
        }

        public override object Clone()
        {
            return new ChipSelection(this);
        }

        #endregion

        #region Ctors 

        static ChipSelection()
        {
            BitmapPath = new string[]
            {
                @"res\Selection\Selection.png",
            };
        }

        public ChipSelection()
        {
            this.FigureBitmap = GetBitMapByFile();
            this.AnimatingPhase = 0;
            this.Scale = 0;
        }

        public ChipSelection(ChipSelection obj)
            : base()
        {
        }

       
        #endregion

        #region private methods

        private Bitmap GetBitMapByFile()
        {
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            return new Bitmap(Image.FromFile(Path.Combine(path, BitmapPath[0])));
        }

        #endregion

    }
}
